<!DOCTYPE html>
<!--suppress ALL -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象</title>
</head>
<body>
<script type="text/javascript">
    /*    function Star(name,country){
            this.name=name;
            this.country=country;
            this.print=function(){
                document.writeln(""+this.name+" "+ this.country+"<br>");
            };
        }

        var star1=new Star();
        star1.name="宋慧乔";
        star1.country="韩国";
        var star2=new Star("范冰冰","中国");
        star1.print();
        star2.print();*/

    //函数也是对象
    /* function Star(name, country) {
         this.name = name;
         this.country = country;
         this.print = function () {
             document.writeln("" + this.name + " " + this.country + "<br>");
         }
     }

     var starOne = new Star()
     starOne.name = "Fritz"
     starOne.country = "China"
     var starTwo = new Star()
     starTwo.name = "Stay"
     starTwo.country = "China"
     starOne.print()
     starTwo.print()*/

    //JavaScript可以利用JSON格式来创建对象
    /* star = {
         name: "范冰冰",
         country: "中国",
         print: function () {
             document.writeln("" + this.name + " " + this.country + "<br>");
         }
     }
     star.print();*/

    //函数也是对象实例
    /*var add = function (a, b) {
        var c = a + b;
        document.writeln(a + "+" + b + "=" + c + "<br>");
    }
    add(9526, 1);
    var result = add instanceof Function;
    document.writeln("函数是否是Function类的实例? ----> " + result + "<br>");*/

    //下面这样子写虽然没有问题,但是重复了type和eat方法应该想法子处理,避免内存冗余
    /* function Dog(name,color){
         this.name=name;
         this.color=color;
         this.type="犬科";
         this.eat=function(){
             document.writeln("Dog eat bone"+"<br>");
         }
     }
     var xiaobai=new Dog("小白","白色");
     xiaobai.eat();
     var xiaohei=new Dog("小黑","黑色");
     xiaohei.eat();*/

    //改进方法
    function Dog(name, color) {
        this.name = name
        this.color = color
    }

    //重复的地方使用prototype存储
    Dog.prototype.type = "犬科"
    Dog.prototype.eat = function () {
        document.writeln("Dog eat bone" + "<br>")
    }
    var xiaobai = new Dog("小白", "白色");
    xiaobai.eat();
    var xiaohei = new Dog("小黑", "黑色");
    xiaohei.eat();
    各店长:明后二天有一档128元赠礼的，
    各店长需提醒门店早上上班开始做好赠品区的陈列与员工主动宣讲，要尽量利用赠品冲高客单，把握最后️天活动销量。
</script>
</body>
</html>